//
//  OrderMessageCell.m
//  sensen_ios
//
//  Created by 小贝 on 16/3/21.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "OrderMessageCell.h"

@interface OrderMessageCell(){
//    UIView *bgView;//背景View
//    UILabel *timeLabel;//时间
//    UILabel *messageContent;
//    UIImageView *proImageView;
//    UILabel *messageDetail;
//    UIButton *lookDetail;

}
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;//时间
@property (weak, nonatomic) IBOutlet UILabel *proDetail;//购买的商品详情
@property (weak, nonatomic) IBOutlet UIImageView *proImageView;//商品图片
@property (weak, nonatomic) IBOutlet UILabel *proDetailLabel;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end
@implementation OrderMessageCell

- (void)awakeFromNib {
    // Initialization code
    _bgView.layer.cornerRadius = 4.0;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setOrderMessageModel:(OrderMessageModel *)orderMessageModel{
    _orderMessageModel = orderMessageModel;
    NSNumber *dateNub = [NSNumber numberWithFloat:[_orderMessageModel.create_time floatValue]];
    NSDate *dateStr = [NSDate getDateFromeNumber:dateNub];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
    NSString *timeStr=[ dateFormatter stringFromDate:dateStr];
    _timeLabel.text = timeStr;
    _proDetail.text = _orderMessageModel.content;
    NSDictionary *dic = [self dictionaryWithJsonString:_orderMessageModel.extra];
    NSString *str = [NSString stringWithFormat:@"%@%@",BOYE_PICTURE_URL,dic[@"image"]];
    NSURL *url = [NSURL URLWithString:str];
    [_proImageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"defaultImage"]];
    _proDetailLabel.text = [NSString stringWithFormat:@"%@,快递单号:%@",_orderMessageModel.content,dic[@"order_code"]];
//    [self createView];
//    [self setViewFrame];
}
#pragma mark---将字符串转换成字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

#pragma mark---不使用Xib
//+ (OrderMessageCell *)orderMessageCellWith:(UITableView *) tableView indentifier:(NSString *)indentifier{
//    OrderMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
//    if (cell == nil) {
//        cell = [[OrderMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
//        cell.backgroundColor = Gray_COLOR;
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    }
//    return cell;
//}
////
//////创建视图
//- (void)createView{
//    timeLabel = [[UILabel alloc] init];
//    timeLabel.textAlignment = NSTextAlignmentCenter;
//    bgView = [[UIView alloc] init];
//    bgView.layer.cornerRadius = 5.0;
//    messageContent = [[UILabel alloc] init];
//    proImageView = [[UIImageView alloc] init];
//    messageDetail = [[UILabel alloc] init];
//    messageDetail.numberOfLines = 0;
//    lookDetail = [[UIButton alloc] init];
//    [lookDetail setTitle:@"查看详情 >" forState:UIControlStateNormal];
//    [lookDetail setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self addSubview:timeLabel];
//    [bgView addSubview:messageContent];
//    [bgView addSubview:messageDetail];
//    [bgView addSubview:proImageView];
//    [bgView addSubview:lookDetail];
//    [self addSubview:bgView];
//    
//}
//////布局
//- (void)setViewFrame{
//    CGFloat margin = 8;//左右间距
//    [timeLabel setFrame:CGRectMake(0, 12, SCREEN_WIDTH, 17)];
//    timeLabel.text = _orderMessageModel.create_time;
//    
//    CGFloat bgView_y = CGRectGetMaxY(timeLabel.frame) + margin;
//    [bgView setFrame:CGRectMake(margin, bgView_y, SCREEN_WIDTH - 2*margin, 120)];
//    bgView.backgroundColor = [UIColor whiteColor];
//    
//    [messageContent setFrame:CGRectMake(18, margin, bgView.frame.size.width-18, 16)];
//    messageContent.text = _orderMessageModel.content;
//    
//    [proImageView setFrame:CGRectMake(18, CGRectGetMaxY(messageContent.frame) +margin, 45, 45)];
//        NSDictionary *dic = [self dictionaryWithJsonString:_orderMessageModel.extra];
//    NSString *str = [NSString stringWithFormat:@"http://sunsun.itboye.com/index.php/Api/Picture/index?id=%@",dic[@"image"]];
//        NSURL *url = [NSURL URLWithString:str];
//    [proImageView setImageWithURL:url placeholderImage:nil];
//    
//    messageDetail.text = [NSString stringWithFormat:@"%@,快递单号:%@",_orderMessageModel.content,dic[@"order_code"]];
//    messageDetail.textColor = [UIColor darkGrayColor];
//    messageDetail.font = [UIFont systemFontOfSize:13];
//    messageDetail.numberOfLines = 3;
//
//    CGFloat messageDetail_width = bgView.frame.size.width -CGRectGetMaxY(proImageView.frame)-margin;
//    CGSize size = [messageDetail sizeThatFits:CGSizeMake(messageDetail_width, MAXFLOAT)];
//
//    [messageDetail setFrame:CGRectMake(CGRectGetMaxX(proImageView.frame)+margin,proImageView.frame.origin.y, messageDetail_width , size.height)];
//    [BoyeViewHandle lineCreatedInView:bgView fram:CGRectMake(0, CGRectGetMaxY(proImageView.frame)+margin, CGRectGetWidth(bgView.frame), 1) color:Gray_COLOR];
//    [lookDetail setFrame:CGRectMake(bgView.frame.size.width-100, CGRectGetMaxY(proImageView.frame)+margin +2, 100, 24)];
//    _height = CGRectGetMaxY(lookDetail.frame)+margin;
//
//}

@end
